import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerHelper;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by wrq on 1/6/17.
 */
public class Html2Pdf {
    public static void main(String[] args) throws IOException, DocumentException {
        String htmlFileName = args[0];
        String pdfFileName = htmlFileName + ".pdf";

        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFileName));
        // step 3
        document.open();
        // step 4
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(htmlFileName));
        //step 5
        document.close();

        System.out.println("PDF Created!");

    }
}
